#ifndef AvcUtmPath_h
#define AvcUtmPath_h

#include "Arduino.h"
#include <EEPROM.h>

#define MAX_WAYPOINTS 40
/*
Perry High
lat: 33.260606
lon: -111.751291
Zone: 12
Easting: 430024
Northing: 3680430

lat: 33.261732
lon: -111.749701
Zone: 12
Easting: 430173
Northing: 3680554

Easting Factor: -1590 -149 = 149m / 1590lon
Northing Factor: -1126 -124 = 124m / 1126lat
*/

class AvcUtmPath {
  int x[MAX_WAYPOINTS];
  int y[MAX_WAYPOINTS];
  byte numberOfWaypoints;
  long commonLatitude;
  long commonLongitude;
  float utmConversionFactorX;
  float utmConversionFactorY;
public:
  inline float getX(int waypoint) {return float(x[waypoint % MAX_WAYPOINTS]) * .001;}
  inline float getY(int waypoint) {return float(y[waypoint % MAX_WAYPOINTS]) * .001;}
  inline byte getNumberOfWaypointsSet () {return numberOfWaypoints;}
  inline float getUtmConversionFactorX() {return utmConversionFactorX;}
  inline float getUtmConversionFactorY() {return utmConversionFactorY;}
  inline float getX(long longitude) {return float(longitude - commonLongitude) * utmConversionFactorX;}
  inline float getY(long latitude) {return float(latitude - commonLatitude) * utmConversionFactorY;}
  inline long getLatitudeForDisplay(int waypoint) {return (getY(waypoint)/utmConversionFactorY) + commonLatitude;}
  inline long getLongitudeForDisplay(int waypoint) {return (getX(waypoint)/utmConversionFactorX) + commonLongitude;}
  void setUtmConversionFactorX(float);
  void setUtmConversionFactorY(float);
  void addWaypoint(long, long);
  void addWaypoint(float, float);
  void resetWaypoints();
  void log(Stream*);
  void writeToEeprom(int);
  
  static AvcUtmPath* getPath(int startAddress) {
    byte size = sizeof(AvcUtmPath);
    byte *path = new byte[size];
    for (int ii = 0; ii < size; ii++) {
      path[ii] = EEPROM.read(startAddress + ii);
    }
    return (AvcUtmPath*) path;
  }
};
#endif
